package com.saa;

import com.saa.common.filter.SessionFilter;
import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@SpringBootApplication(exclude=FreeMarkerAutoConfiguration.class)
@EnableCircuitBreaker
// MyBatis Mapper包扫描路径
@MapperScan({"com.saa"})
// Spring 组件包扫描路径
//@ComponentScan(basePackages = {"com.saa"})
@ServletComponentScan
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableAsync
@EnableCaching
@EnableFeignClients
@EnableHystrix
//@EnableEncryptableProperties
public class SaaCloudApplication {


    public static void main(String[] args) {
        SpringApplication.run(SaaCloudApplication.class, args);
    }

    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        SessionFilter sessionFilter = new SessionFilter();
        registrationBean.setFilter(sessionFilter);
        List<String> urlPatterns = new ArrayList<String>();
        urlPatterns.add("/*");
        Map<String,String> params = new HashMap<String,String>();
        //需要将servlet的url写在这里
        params.put("excludedPages", "/login");
        registrationBean.setInitParameters(params);
        registrationBean.setUrlPatterns(urlPatterns);
        return registrationBean;
    }

}
